package com.leyou.upload.web;

import com.leyou.upload.service.UploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * @package com.leyou.upload.web
 * @description: 上传服务的控制层
 * @author: 许超越
 * @date 2019/6/25 16:55
 * @version: V1.0
 */
@RestController
public class UploadController {

    @Autowired
    private UploadService uploadService;

    /**
     * 新增商品出的图片logo上传
     *
     * @return
     * @param: file
     */
    @PostMapping("/image")
    public ResponseEntity<String> uploadImage(@RequestParam("file") MultipartFile file) {
        //添加成功，返回返回的状态码和添加成功的图片路径
        return ResponseEntity.ok(uploadService.uploadImage(file));
    }

    /**
     * 获取阿里云服务的签名认证
     * @return
     */
    @GetMapping("signature")
    public ResponseEntity<Map<String, Object>> getAliSignature() {
        return ResponseEntity.ok(uploadService.getAliSignature());
    }
}
